package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.MessageInfo;
import cn.wolfcode.trip.base.query.MessageInfoQueryObject;
import cn.wolfcode.trip.base.service.IMessageInfoService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/messageInfo")
public class MessageInfoController {

    @Autowired
    private IMessageInfoService messageInfoService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") MessageInfoQueryObject qo) {
        qo.setOrderBy("createTime DESC");
        PageInfo pageInfo = messageInfoService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "messageInfo/list";
    }

    @RequestMapping("/save")
    @ResponseBody
    public JsonResult save(MessageInfo messageInfo) {
        messageInfoService.save(messageInfo);
        return new JsonResult();
    }
}
